// pages/recruit/personal/resume/addeducation/addeducation.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proficiency: ["一般", "熟悉", "掌握", "专家"],
    prokey: 0,
    language: {
      type: "",
      proficiency: "一般",
      grade: ""
    },
    state: "new", //默认新建，进来时带有状态时则变为修改。
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const that = this;
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('crossdata', function(res) {
      that.data.prokey = that.data.proficiency.indexOf(res.data.proficiency)
      that.setData({
        prokey: that.data.prokey,
        language: res.data,
        state: "edit"
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  typeinput: function(e) {
    const that = this;
    that.data.language.type = e.detail.value;
    that.setData({
      language: that.data.language,
    })
  },
  proficiency: function(e) {
    const that = this;
    that.data.language.proficiency = that.data.proficiency[parseInt(e.detail.value)];
    that.setData({
      language: that.data.language,
      prokey: parseInt(e.detail.value)
    })
  },
  gradeinput: function(e){
    const that = this;
    that.data.language.grade = e.detail.value;
    that.setData({
      language: that.data.language,
    })
  },
  back: function() {
    wx.navigateBack({})
  },
  commit: function() {
    const that = this;
    var box = that.data.language;
        console.log(box)
    var title;
    if (box.type == "") {
      title = "请输入擅长语言"
    } else if (box.grade == "") {
      title = "请输入语言的熟练等级"
    } else {
      if (that.data.state == "new") {
        console.log("新建")
      } else {
        console.log("commit")
      }
      return;
    }
    wx.showToast({
      title: title,
      icon: "none",
      duration: 1000
    })
  }
})